home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 16 - KnowAboutIt (19xx)(Topik Public Domain)(PD)[WB].zip / Topik - Disk 16 - KnowAboutIt (19xx)(Topik Public Domain)(PD)[WB].adf / MicroRayDbw / uray.c < prev    next >
C/C++ Source or Header  |  1988-12-11  |  6KB  |  215 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *            Copyright (c) 1988, David B. Wecker            *
  4.  *                All Rights Reserved                *
  5.  *                                    *
  6.  * This file is part of DBW_uRAY                    *
  7.  *                                    *
  8.  * DBW_uRAY is distributed in the hope that it will be useful, but    *
  9.  * WITHOUT ANY WARRANTY. No author or distributor accepts        *
  10.  * responsibility to anyone for the consequences of using it or for    *
  11.  * whether it serves any particular purpose or works at all, unless    *
  12.  * he says so in writing. Refer to the DBW_uRAY General Public        *
  13.  * License for full details.                        *
  14.  *                                    *
  15.  * Everyone is granted permission to copy, modify and redistribute    *
  16.  * DBW_uRAY, but only under the conditions described in the        *
  17.  * DBW_uRAY General Public License. A copy of this license is        *
  18.  * supposed to have been given to you along with DBW_uRAY so you    *
  19.  * can know your rights and responsibilities. It should be in a file    *
  20.  * named COPYING. Among other things, the copyright notice and this    *
  21.  * notice must be preserved on all copies.                *
  22.  ************************************************************************
  23.  *                                    *
  24.  * Authors:                                *
  25.  *    DBW - David B. Wecker                        *
  26.  *                                    *
  27.  * Versions:                                *
  28.  *    V1.0 881023 DBW    - First released version            *
  29.  *    V1.1 881110 DBW - Fixed scan coherence code            *
  30.  *    V1.2 881125 DBW - Removed ALL scan coherence code (useless)    *
  31.  *              added "fat" extent boxes            *
  32.  *                                    *
  33.  ************************************************************************/
  34.  
  35. #define URAY_MAIN 1
  36. #include "uray.h"
  37.  
  38. /************************************************************************/
  39. /************* top level routines ***************************************/
  40. /************************************************************************/
  41.  
  42. /* ray trace 1 pixel on the screen and store it away */
  43. dotrace(v1)
  44. VEC    v1;
  45.     {
  46.     int        i;
  47.     VEC        v2;
  48.  
  49.     /* compute the point we're looking at (from 0,0,0) */
  50.      v1[0] = (double)col-(double)cols/2.0;
  51.  
  52.     /* normalize the direction, and ray trace it */
  53.     vunit(v1,v2);
  54.     trace(-1, 1.0, BLACK, v2, v2, NULL);
  55.  
  56.     /* scale the color and store it */
  57.     for (i=0; i<3; i++) {
  58.     if (v2[i] < 0.0) v2[i] = 0.0;
  59.     if (v2[i] > 1.0) v2[i] = 1.0;
  60.     outary[i][col] = (unsigned char)(v2[i]*255.9);
  61.     }
  62.  
  63. #if DEBUG_pixels
  64.     printf("(%3d,%3d) = [%02x %02x %02x] [%4.2f %4.2f %4.2f]\n",
  65.     row,col,outary[0][col],outary[1][col],outary[2][col],v2[0],v2[1],v2[2]);
  66. #endif
  67.  
  68.     }
  69.  
  70.  
  71. /* interrupt handler for any errors */
  72. handler(sig) {
  73.     leave("signal %d received... exiting",sig);
  74.     }
  75.  
  76.  
  77.  
  78. main(argc,argv)
  79. char    **argv;
  80.     {
  81.     int        i,j;
  82.     VEC        v1;
  83.  
  84.     /* definitions for doing elapsed user time */
  85.     double  dtime;
  86. #   ifdef U__X
  87.     struct  tms        etime;
  88. #    endif
  89. #   ifdef VMS
  90.     struct    tbuffer     etime;
  91.     double            btime;
  92. #    endif
  93. #   ifdef AMIGA
  94.     unsigned long        bsecs,bmicros,csecs,cmicros;
  95.     struct IntuitionBase    *OpenLibrary();
  96. #    endif
  97.  
  98.     printf(VERSION);
  99.  
  100.     /* grab as many errors as possible */
  101.     signal(SIGINT,handler);    /* ^C hit  */
  102.     signal(SIGFPE,handler);    /* floating point error (/ 0) */
  103.     signal(SIGILL,handler);    /* illegal instruction */
  104.     signal(SIGSEGV,handler);    /* segmentation violation (addr err) */
  105.  
  106.     /* Get the starting time */
  107. #   ifdef AMIGA
  108.     IntuitionBase = OpenLibrary("intuition.library",0L);
  109.     if (!IntuitionBase) exit(0);
  110.  
  111.     CurrentTime(&bsecs,&bmicros);
  112. #   endif
  113.  
  114.  
  115. #   ifdef VMS
  116.     times(&etime);
  117.     btime = ((double)etime.proc_user_time)/100.0;
  118. #    endif
  119.  
  120.     /* get a base file name */
  121.     if (argc > 1) basnam = argv[1];
  122.  
  123.     /* get all the object definitions in to memory */
  124.     readinput();
  125.  
  126.     /* build a tree of object extents */
  127.     doextents();
  128.  
  129. #   if DEBUG_dumpnodes
  130.     dumpnodes(nodes,0);
  131. #    endif
  132.  
  133.     /* get the current time (after setting up extents) */
  134. #   ifdef U__X
  135.     times(&etime);
  136.     dtime = ((double)etime.tms_utime)/60.0;
  137. #    endif
  138.  
  139. #   ifdef VMS
  140.     times(&etime);
  141.     dtime = ((double)etime.proc_user_time)/100.0 - btime;
  142. #    endif
  143.  
  144. #   ifdef AMIGA
  145.     CurrentTime(&csecs,&cmicros);
  146.     if (cmicros < bmicros) {
  147.         cmicros += 1000000;
  148.         csecs   -= 1;
  149.         }
  150.     dtime  =  (double)(csecs-bsecs);
  151.     dtime += ((double)(cmicros-bmicros)) / 1000000.0;
  152. #    endif
  153.  
  154.     printf("\nExtent setup time: %12.2f\n\n",dtime);
  155.  
  156.     /* compute the number of output bytes in a scan line */
  157.     if        (bpp == 24) obpsl = cols;
  158.     else if (bpp == 12) obpsl = cols >> 1;
  159.     else if (bpp) leave("BPP must be either 12, 24 or 0");
  160.     bpp        /= 3;
  161.  
  162.     /* create output files */
  163.     coutputs();
  164.  
  165.     /* define depth of the screen */
  166.     v1[2] = ((double)(rows+cols))/4.0/tan((double)aov/114.5915590261);
  167.  
  168.     /* now ray trace each pixel */
  169.     for (row=startrow; row<endrow; row++) {
  170.  
  171.     /* define row we're looking at */
  172.     v1[1] = ((double)rows/2.0-(double)row) * aspect;
  173.  
  174.     /* ray trace all pixels */
  175.     for (col=0; col<cols; col++) dotrace(v1);
  176.  
  177.     /* output the line */
  178.     woutputs((short)row);
  179.  
  180.     }
  181.  
  182.     printf("\n\n");
  183.  
  184.  
  185.     /* get the ending elapsed time */
  186. #   ifdef U__X
  187.     times(&etime);
  188.     dtime = ((double)etime.tms_utime)/60.0;
  189. #    endif
  190.  
  191. #   ifdef VMS
  192.     times(&etime);
  193.     dtime = ((double)etime.proc_user_time)/100.0 - btime;
  194. #    endif
  195.  
  196. #   ifdef AMIGA
  197.     CurrentTime(&csecs,&cmicros);
  198.     if (cmicros < bmicros) {
  199.         cmicros += 1000000;
  200.         csecs   -= 1;
  201.         }
  202.     dtime  =  (double)(csecs-bsecs);
  203.     dtime += ((double)(cmicros-bmicros)) / 1000000.0;
  204. #    endif
  205.  
  206.     printf("\nTotal  run   time: %12.2f\n\n",dtime);
  207.     printf("False hits: Extents = %10d, Nodes = %10d\n",fehits,fnhits);
  208.     printf("Good  hits: Extents = %10d, Nodes = %10d\n",gehits,gnhits);
  209.     printf("Total hits: Extents = %10d, Nodes = %10d\n\n",
  210.     fehits+gehits,fnhits+gnhits);
  211.  
  212.     /* all done, so finish up */
  213.     leave(NULL);
  214.     }
  215.